package task3;

import java.util.ArrayList;
import java.util.Scanner;

public class test3 {

    static Scanner input=new Scanner(System.in);

    static ArrayList<Integer>  entrance=new ArrayList<>();

    static ArrayList<ArrayList<Integer>> resort=new ArrayList<>();


    public static void main(String[] args) {

        int n= input.nextInt();

        for(int i=0;i<n;i++)
            entrance.add(input.nextInt());

        resort();
        print();
    }

    private static void resort() {

        int index=0;
        int last=entrance.get(0);
        int count=0;
        int rest=entrance.size();

        ArrayList<Integer> using=null;


        while (entrance.size()>0){

            Integer train=entrance.get(index);

            if (count==0)
                using=new ArrayList<>();

            if(train<=last){
                using.add(train);
                entrance.remove(train);
                last=train;
            }else {
                index++;
            }

            count++;

            if(count==rest)
            {
                resort.add(using);
                count=0;
                index=0;
                last=entrance.size()>0?entrance.get(0):0;
                rest=entrance.size();
            }

        }

    }

    private static void print(){
        for(int i=0;i<resort.get(0).size();i++){
            if(i<resort.get(0).size()-1){
                System.out.print(resort.get(0).get(i)+" ");
            }
            else {
                System.out.print(resort.get(0).get(i));
            }

        }
        System.out.println("\n"+resort.size());
    }

}
